package com.hd.crdao.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.bean.GetStoreAuthdataBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.ALog;
import com.hd.crdao.utils.SPUtils;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.view.ExpandHeadView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import okhttp3.Call;

/**
 *
 *@author Programming
 *@date 2017/6/27 0027
 */

public class CertPassActivity extends BaseSecondActivity {

    @BindView(R.id.certpass_head)
    ExpandHeadView mCertpassHead;
    @BindView(R.id.certInfo)
    TextView mCertInfo;
    @BindView(R.id.name)
    TextView mName;
    @BindView(R.id.phonenumber)
    TextView mPhonenumber;
    @BindView(R.id.idcardnumber)
    TextView mIdcardnumber;
    @BindView(R.id.body)
    LinearLayout mBody;
    @BindView(R.id.enterMyShop)
    Button mEnterMyShop;
    public GetStoreAuthdataBean.StoreAuthdataBean mStoreAuthdata;

    @Override
    protected void initView() {
        initData();
        mEnterMyShop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(UIUtils.getContext(), MyShopActivity.class));
                finish();
            }
        });
    }

    private void initData() {
        OkHttpUtils.post().url(Constants.GETSTOREAUTHDATA_URL)
                .addParams("sign", Constants.SIGN)
                .addParams("carBusinessId", SPUtils.getString("businessid", ""))
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                ALog.d(response);
                mStoreAuthdata = new Gson().fromJson(response, GetStoreAuthdataBean.class).getStoreAuthdata();
                String name = mStoreAuthdata.getIdcardName();
                String newname = name.substring(1,name.length());
                mCertInfo.setText("亲爱的*" + newname + ",您的身份已经通过认证");
                mName.setText("*" + newname);
                String idcardNum = mStoreAuthdata.getIdcardNum();
                String phoneNumber = SPUtils.getString("phoneNumber", "");
                mPhonenumber.setText(phoneNumber);
                mIdcardnumber.setText(idcardNum.substring(0,1)+
                        "*****************"+
                        idcardNum.substring(idcardNum.length()-2,idcardNum.length()-1));

            }
        });
        /*mCertInfo.setText(mStoreAuthdata.getIdcardName());
        mName.setText(mStoreAuthdata.getIdcardName());
        mPhonenumber.setText(mStoreAuthdata.getp);
        mIdcardnumber.setText(mStoreAuthdata.getIdcardNum());
        mCertAddress.setText(mStoreAuthdata.);*/
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_certpass;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mCertpassHead;
    }


}
